a = input('Введите последовательность:')
last = 0
stack = []
if a[0] == ')' or a[0] == '}' or a[0] == ']' or a[0] == '>':
    print(False)
else:
    for i in a:
        if i not in '({[<)}]>':
            continue  
        if i in '({[<':
            stack.append(i)
            last = stack[-1]
            if ((i == '(' and last == ')') 
                or (i == '{' and last == '}')
                or (i == '[' and last == ']')
                or (i == '<' and last == '>')):
                stack.pop()
        if i in ')}]>':
            stack.append(i)
            last = stack[-1]
            if ((i == ')' and last == '(') 
                or (i == '}' and last == '{')
                or (i == ']' and last == '[')
                or (i == '>' and last == '<')):
                stack.pop()
            else:
                break        
    if len(stack) == 0:
        print(True)
    else:
        print(False)        
